Skip to content

Fix MetricsDashboard::selected_index() to return Option<usize>#115

Merged
ryanoneill merged 1 commit intomainfrom
fix/metrics-dashboard-selected-index
Mar 2, 2026
Merged

Fix MetricsDashboard::selected_index() to return Option<usize>#115
ryanoneill merged 1 commit intomainfrom
fix/metrics-dashboard-selected-index

Conversation

@ryanoneill
Copy link
Owner

Summary

  • Change selected field from usize to Option<usize> for correctness
  • selected_index() now returns Option<usize> (was usize)
  • selected_position() now returns Option<(usize, usize)> (was (usize, usize))
  • Empty dashboard reports None instead of 0 pointing to nothing

Context

All other Envision components return Option<usize> from their index methods. MetricsDashboard was the outlier returning a bare usize. When the widgets vec was empty, selected_index() returned 0 which was misleading.

Test plan

  • All 66 MetricsDashboard unit tests pass
  • 4 doc tests pass (including updated module-level doc test)
  • New test_empty_dashboard_selected_index_is_none covers the empty case
  • cargo clippy --all-targets --all-features -- -D warnings clean

🤖 Generated with Claude Code

@codecov-commenter
Copy link

codecov-commenter commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.64%. Comparing base (e096986) to head (5bcacb8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #115   +/-   ##
=======================================
  Coverage   92.64%   92.64%           
=======================================
  Files         100      100           
  Lines        9545     9549    +4     
=======================================
+ Hits         8843     8847    +4     
  Misses        702      702           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Change the internal selected field from usize to Option<usize> so that
an empty dashboard correctly reports no selection (None) instead of
returning 0 pointing to nothing.

- Change selected field from usize to Option<usize>
- Default state uses None, new() uses Some(0) when widgets exist
- selected_index() now returns Option<usize>
- selected_position() now returns Option<(usize, usize)>
- Update all navigation logic to wrap/unwrap Option
- Update view() to use Option comparison
- Update all test assertions to expect Some(value)
- Add test_empty_dashboard_selected_index_is_none test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ryanoneill ryanoneill force-pushed the fix/metrics-dashboard-selected-index branch from 30f67af to 5bcacb8 Compare March 2, 2026 16:44
@ryanoneill ryanoneill merged commit cc8cc55 into main Mar 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants